const mixins = require('../../../mixins/forum')
const common = require('../../../mixins/common')
var app = getApp();
const options = {
  /**
   * 页面的初始数据
   */
  data: {
    posts: [],
    page: 1,
    tabs: [{ name: "帖子", id: 0,isComment:false }, { name: "评论", id: 1,isComment:true }],
    tabIndex:0,
    isComment:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getReviewLists();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

    /**
   * 取消
   */
  onClickCancle: function () {
    this.setData({
      showDialog: !this.data.showDialog
    })

  },

  deletePosts: function (e) {
    let index=e.currentTarget.dataset.index;
    let id=e.currentTarget.id;;
    this.setData({
      delindex:index,
      id:id,
      bounced: true,
    })
  },

  onClickCancle:function(){
    this.setData({
      bounced: false,
    })
  },

    /**
   * 取消删除
   */

  bouncedTap: function () {
    this.setData({
      bounced: !this.data.bounced
    })
  },

  review:function(e){
   let id=e.currentTarget.id;
   let index=e.currentTarget.dataset.index;
   this.setData({
    delindex:index,
    id:id,
  })
  if(this.data.isComment)
  {
    this.reviewComments();
  }
  else{
  this.reviewPosts();
  }
  },

   /**
  * 菜单切换
  */
 changeTab: function (e) {

  let index = e.currentTarget.dataset.index;
  let isComment=e.currentTarget.dataset.iscomment;
  console.log(e);
  let that = this;
  this.setData({
    page: 1,
    posts:[],
    showSkeleton: true,
    messageList: [],
    isLastPage: false,
    isBottom: false,
    tabIndex: index,
    isComment:isComment,
  })
  if (index == 0) {
    this.getReviewLists();
  }
  if (index == 1) {
   this.getCommentList();
  }
},



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let user = app.globalData.user
    if (!user) {
      user = '';
    }
    this.setData({
      user: user,
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      page: 1,
      posts:[],
      showSkeleton: true,
      messageList: [],
      isLastPage: false,
      isBottom: false
    })
    if (this.data.tabIndex == 0) {
      this.getReviewLists();
    }
    if (this.data.tabIndex == 1) {
     this.getCommentList();
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      isBottom: true
    })
    if (!this.data.isLastPage) {
      if(this.data.tabIndex==0)
      {
      this.getReviewLists({
        page: this.data.page,
      });
    }
    else{
      this.getCommentList({
        page: this.data.page,
      });
    }
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
}



mixins(options)
common(options)
Page(options)